﻿using System;
using System.Collections.Generic;
using System.Linq;
using ThumpThumpBus.Models.Domain;

namespace ThumpThumpBus.Models.Repository
{
    public class IncidentRepository
    {
        private static readonly List<Incident> _incidents = new List<Incident>()
                        {
                            new Incident { id = 1, reason = "You broke the build with your crap code.", assailantId = PersonRepository.People[0].id, victimId = PersonRepository.People[2].id },
                            new Incident { id = 2, reason = "Your code looked really bad.", assailantId = PersonRepository.People[1].id, victimId = PersonRepository.People[3].id },
                            new Incident { id = 3, reason = "You broke the unit test... again.  Please stop.", assailantId = PersonRepository.People[2].id, victimId = PersonRepository.People[4].id },
                            new Incident { id = 4, reason = "You just ruined my life with your crappy code.", assailantId = PersonRepository.People[3].id, victimId = PersonRepository.People[0].id },
                            new Incident { id = 5, reason = "Have you written code before?  I have a book you can borrow.", assailantId = PersonRepository.People[4].id, victimId = PersonRepository.People[1].id },
                            new Incident { id = 6, reason = "Your code is the reason I will have a job.", assailantId = PersonRepository.People[4].id, victimId = PersonRepository.People[2].id },
                            new Incident { id = 7, reason = "Your code was awesome.  Thank you for making it easy to get on the DailyWTF front page.", assailantId = PersonRepository.People[4].id, victimId = PersonRepository.People[3].id },
                            new Incident { id = 8, reason = "You know it is ok to check in code that compiles.", assailantId = PersonRepository.People[3].id, victimId = PersonRepository.People[1].id },
                            new Incident { id = 9, reason = "Hey thanks for giving me another reason I shouldn't come in today.", assailantId = PersonRepository.People[2].id, victimId = PersonRepository.People[4].id }
                        };

        public void AddIncident(Incident incident)
        {
            _incidents.Add(incident);
        }

        public Incident GetIncidentById(int id)
        {
            return _incidents.Find(a => a.id == id);
        }

        public int GetHitCountByPerson(Person person)
        {
            return _incidents.Count(a => a.victimId == person.id);
        }

        public int GetThrowCountByPerson(Person person)
        {
            return _incidents.Count(a => a.assailantId == person.id);
        }

        public IEnumerable<Incident> GetAllIncidents()
        {
            return _incidents;
        }

        public IEnumerable<Incident> GetAllIncidentsByPerson(Person person)
        {
            return _incidents.Where(a => a.assailantId == person.id || a.victimId == person.id);
        }

        public IEnumerable<Incident> GetAllIncidentsByAssailant(Person assailant)
        {
            return _incidents.Where(a => a.assailantId == assailant.id);
        }

        public IEnumerable<Incident> GetAllIncidentsByVictim(Person victim)
        {
            return _incidents.Where(a => a.victimId == victim.id);
        }
    }
}